import api from '@/api/note/banner'
import { listNc } from '@/api/mall/category'
import { listGoodsByCategory } from '@/api/mall/goods'
import { getToken } from '@/utils/auth'
import { mapGetters } from 'vuex'
export default {
  name: 'Index',
  data() {
    return {
      bannerList: undefined,
      userForm: {},
      cats: undefined,
      goods: undefined,
      userData: undefined
    }
  },
  computed: {
    ...mapGetters([
      'user'
    ]),
    isLogin() {
      return !!getToken()
    }
  },
  created() {
    api.list().then(res => {
      this.bannerList = res.data.data.records
    })
    listNc().then(res => {
      this.cats = res.data.data.records
    })
    listGoodsByCategory(115).then(res => {
      this.goods = res.data.data.records
    })
  },
  methods: {
    login() { // 登录方法
      const user = { ...this.userForm }
      user.username = `mblu2_${user.username}`
      this.$store.dispatch('LoginByUsername', user).then(() => {
        this.$router.go(0)
      })
    },
    logout() {
      this.$store.dispatch('FedLogOut').then(() => {
        this.$router.go(0)
      })
    },
    intoAdmin() {
      console.log(window)
      window.location.href = 'http://47.104.167.116/ncp/admin/'
    }
  }
}
